<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>日志</title>
    <script src="../../../../res/js/jquery-3.4.1.min.js" charset="utf-8"></script>
    <script src="../../../../res/js/login_common.js" charset="utf-8"></script>
    <script src="../../../../res/layui/layui.js" charset="utf-8"></script>
    <script src="../../../../res/js/Tools.js" charset="utf-8"></script>
    <script src="../../../../res/js/error.js" charset="utf-8"></script>
    <link rel="shortcut icon" type="image/x-icon" href="../../../../res/images/favicon.ico">
    <link rel="stylesheet" href="../../../../res/layui/css/layui.css" media="all">
    <style type="text/css">
        .fonts {
            line-height: 40px;
        }

        .deletes {
            width: 60px;
            height: 40px;
            /*border:1px solid;*/
            float: right;
            color: #0aafe6;
        }

        .deletes:hover {
            cursor: pointer;
            color: #bd2c00
        }

        .select {
            width: 100%;
            position: fixed;
            z-index: 999;
            background: white;
        }
    </style>
</head>
<body style="padding: 10px">
<form class="layui-form" action="">
    <div class="select">
        <div class="layui-inline">
            <label class="layui-form-label">创建时间</label>
            <div class="layui-input-inline">
                <input type="text" name="date" id="date" lay-verify="date" placeholder="开始时间" autocomplete="off"
                       class="layui-input" style="width: 150px">
            </div>
            <div class="layui-input-inline">
                <input type="text" name="date" id="date1" lay-verify="date" placeholder="结束时间" autocomplete="off"
                       class="layui-input" style="width: 150px">
            </div>
        </div>

        <div class="layui-inline">
            <label class="layui-form-label">输入关键字</label>
            <div class="layui-input-inline">
                <input type="text" name="logTitle" id="logTitle" placeholder="请输入关键字"
                       autocomplete="off"
                       class="layui-input" style="width: 150px">
            </div>
        </div>

        <div class="layui-input-inline">
            <label class="layui-form-label">
                <input type="button" class="layui-btn layui-btn-normal" id="isAll" value="查询">
            </label>
        </div>
    </div>
</form>
<div style="margin-top: 97px">

</div>
<table class="layui-hide" id="test" lay-filter="test"></table>

<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-xs layui-btn-normal" lay-event="see">查看</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>


<script type="text/html" id="toolbarDemo">
    <div class="layui-btn-container">
        <button class="layui-btn layui-btn-danger" lay-event="delete">批量删除</button>
        <button class="layui-btn layui-btn-normal" lay-event="add">新增</button>
    </div>
</script>

<script>
    var table2;
    // 修改赋值
    var logType = getQueryString("logType");
    layui.use(['form', 'table', 'layedit', 'laydate'], function () {
        var table = layui.table
            , layer = layui.layer
            , layedit = layui.layedit
            , laydate = layui.laydate
            , form = layui.form;
        table2 = table.render({
            elem: '#test'
            , url: '../../../../OaLogAction/findAll?logType=' + logType
            , headers: {token: token}
            , toolbar: '#toolbarDemo' //开启头部工具栏，并为其绑定左侧模板
            , title: '系统日志'
            , parseData: function (res) {
                /*if (res.code == 500) {
                    return false
                }*/
                return {
                    "code": res.data.code,
                    "msg": res.data.msg,
                    "count": res.data.count,
                    "data": res.data.data
                };
            }
            , cols: [[
                {type: 'checkbox', fixed: 'left'}
                , {type: 'numbers', title: '序列', fixed: 'left'}
                , {field: 'logTitle', title: '所属模块', width: 200}
                , {field: 'logIp', title: 'ip地址', width: 130}
                , {field: 'logBody', title: '日志详情'}
                , {
                    field: 'createdTime', title: '创建时间', width: 160, templet: function (row) {
                        if (row.createdTime) {
                            return dateFormat("yyyy-MM-dd hh:mm:ss", new Date(row.createdTime));
                        } else {
                            return "";
                        }
                    }
                }
                , {fixed: 'right', title: '操作', toolbar: '#barDemo', width: 220}
            ]]
            , page: true
        });

        //日期
        laydate.render({
            elem: '#date'
        });
        laydate.render({
            elem: '#date1'
        });

        $("#isAll").on("click", function () {
            table2.reload({
                where: {
                    startDate: $("#date").val(),
                    endDate: $("#date1").val(),
                    logTitle: $("#logTitle").val()
                },
                page: {
                    curr: 1
                }
            })
        });


        //监听行单击事件（双击事件为：rowDouble）
        /*table.on('row(test)', function (obj) {
            var data = obj.data;
            var url = "../../streetAction/findAll";
            $.post(url, {sectorId: data.clientId, streetName: "0"}, function (obj) {
                $("#TenementStreet").html("");
                $.each(obj, function (index, item) {
                    console.info(window.loginObj.manager.userType);
                    $("#TenementStreet").append('<div style="font-size: 20px;margin-left: 100px;margin-right: 50px"><div>' + item.userName + '</div><div style="font-size: 15px;margin-top: 10px">' + item.sectorName + '</div><div style="float: right;font-size: 20px">' + dateFormat("yyyy-MM-dd hh:mm:ss", new Date(item.createdTime)) + '</div><hr></div>');
                });
                console.info();
            }, "json");

            /!*layer.alert(JSON.stringify(data), {
                title: '当前行数据：'
            });*!/
        });*/

        $('#clientName').bind('keypress', function (event) {
            if (event.keyCode == "13") {
                event.preventDefault();
                //回车执行查询
                $('#isAll').click();
            }
        });

        //监听头工具栏事件
        table.on('toolbar(test)', function (obj) {
                var checkStatus = table.checkStatus(obj.config.id); //获取选中的数据
                switch (obj.event) {
                    case 'add':
                        var data = checkStatus.data;
                        layer.open({
                            type: 2,
                            title: '增加操作',
                            shadeClose: true,
                            shade: false,
                            maxmin: true, //开启最大化最小化按钮
                            area: ['90%', '90%'],
                            content: 'logFrom.html'
                        });
                        break;
                    case 'delete':
                        var data = checkStatus.data;
                        if (data.length === 0) {
                            layer.msg('请选择一行');
                        } else {
                            //询问框
                            layer.confirm('是否删除数据?', {
                                btn: ['确定', '取消'] //按钮
                            }, function () {
                                var ids = [];
                                var data = checkStatus.data;
                                for (var i = 0; i < data.length; i++) {
                                    ids.push(data[i].pkLogId);
                                }
                                $.ajax({
                                    cache: false,
                                    url: getRootPath()+"OaLogAction/deleteAll",
                                    data: {ids: ids},
                                    headers: {token: token},
                                    type: "DELETE",
                                    success: res => {
                                        if (res.data.code === 1) {
                                            table2.reload();
                                            layer.msg('删除成功', {icon: 1});
                                        } else if (res.data.code === 500) {
                                            error('500')
                                        } else {
                                            layer.msg("删除失败");
                                        }
                                    },
                                    error: res => {
                                        error('404')
                                    }
                                });

                                /*var datas = {"ids": ids};
                                $.delete(url, datas, function (obj) {
                                    if (obj.num == 1) {
                                        table2.reload();
                                        layer.msg('删除成功', {icon: 1});
                                    } else {
                                        layer.msg("删除失败")
                                    }
                                });*/
                            }, function () {

                            })
                        }
                        break;
                }
            }
        );

        //监听行工具事件
        table.on('tool(test)', function (obj) {
            var data = obj.data;
            //console.log(obj)
            if (obj.event === 'del') {
                layer.confirm('真的删除行么', function (index) {
                    $.ajax({
                        cache: false,
                        url: '../../../../OaLogAction/deleteById/' + data.pkLogId,
                        headers: {token: token},
                        type: 'DELETE',
                        success: res => {
                            if (res.data.code === 1) {
                                table2.reload();
                                layer.msg('删除成功', {icon: 1});
                            } else if (res.data.code === 500) {
                                error('500')
                            } else {
                                layer.msg("删除失败")
                            }
                        },
                        error: res => {
                            error('404')
                        }
                    })
                });
            } else if (obj.event === 'see') {
                layer.open({
                    type: 2,
                    title: '查看',
                    shadeClose: true,
                    shade: false,
                    maxmin: true, //开启最大化最小化按钮
                    area: ['90%', '90%'],
                    content: 'logShow.html?pkLogId=' + data.pkLogId
                });
            }
        });
    });
</script>
</body>
</html>